'''

@author: noako
'''

import Parser
from DCEL import DCEL
import LAV  
from heapq import heappop
import sys
from GeometryHelper import ParallelEdgesError
try:
    # for Python2
    import tkMessageBox
except ImportError:
    # for Python3
    import tkinter.messagebox as tkMessageBox

try:
    vertices,filename = Parser.ParseInput()
    if vertices == None: sys.exit()
    dcel = DCEL(vertices)
    event_queue = []
    LAV.CreateSLAV(dcel.GetInnerPolygonEdge(), event_queue)
    while (len(event_queue) != 0):
        event = heappop(event_queue)
        event.Handle(dcel, event_queue)
    Parser.ParseOutput(filename+".out", dcel)
except ParallelEdgesError as e:
    tkMessageBox.showerror("Input Error", e.msg)


